package com.its.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.its.member.mapper.MemberMapper;
import com.its.member.pojo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.awt.geom.QuadCurve2D;
import java.util.Collections;

@Service
public class MemberDetailServiceImpl implements UserDetailsService {
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public UserDetails loadUserByUsername(String memberAccount) throws UsernameNotFoundException {
        //1.根据用户名查询会员信息
        QueryWrapper<Member> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_account",memberAccount);
        Member member = memberMapper.selectOne(queryWrapper);
        if (member == null) {
            throw new UsernameNotFoundException("用户名不存在");
        }
        return new User(member.getMemberAccount().toString(), member.getMemberPassword(), Collections.emptyList());
    }
}
